home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0574.ZIP
/
SDATIM.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-11-21
|
2KB
|
132 lines
include compiler.inc
ttl SDATIM, 1.05, 10-30-86, jk
dseg
clknam db 'CLOCK$',0
days dw 0 ; buffer for CLOCK$
minits db 0
hrs db 0
hdths db 0
secs db 0,0
months db 31,28,31,30,31,30,31,31,30,31,30,31
cseg
; void sdate(dest) char dest[9]; /* puts system date in DEST as string */
procdef sdate,<<dest, ptr>>
pushreg
call rdclk ; read the CLOCK$
jc quit
mov ax, days
mov dx,75 ; 1-1-80 offset
gly: add dl,4 ; scale out leapyears
sub ax,1461
jns gly
add ax,1461
cmp ax,59 ; test for leapyear
jb gyr ; no adjustment needed
jne lya ; adjust if not leap day
inc dl
push dx ; year
mov al,29
push ax ; day
mov al,2
jmp short olyr ; spit it out
lya: dec ax ; remove leap day from count
gyr: inc dl ; and find the year
sub ax,365
jns gyr
add ax,365
push dx ; save year
mov bx,-1
gmo: inc bx ; find the month
mov dl,months[bx]
sub ax,dx
jns gmo
add ax,dx ; correct day count
inc ax ; (CLOCK$ is zero-based)
xchg ax,bx
push bx ; save day
inc al ; adjust month
olyr:
ldptr di, dest ; initialize the pointer
call outi ; month (initialize OUT)
mov al, '/'
stosb
pop ax ; day
call outn
mov al, '/'
stosb
pop ax ; year
call outn
xor ax, ax
stosb
quit: pret
pend sdate
; void stime(dest) char dest[12]; /* puts system time in DEST as string */
procdef stime,<<dest1, ptr>>
pushreg
call rdclk ; read the CLOCK$
jc tquit
ldptr di, dest1 ; initialize the pointer
mov al, hrs ; hours
call outi
mov al, ':'
stosb
mov al, minits ; minutes
call outn
mov al, ':'
stosb
mov al, secs ; seconds
call outn
mov al, '.'
stosb
mov al, hdths ; hundredths
call outn
xor ax, ax
stosb
tquit: pret
pend stime
internal outi ; put 2 digits where ES:DI points
cld
outn: mov ah,'0'
cmp al,9
jbe unit
ten: inc ah ; count tens
sub al,10
cmp al,9
ja ten
unit: add al,'0'
xchg ah,al ; save units
stosb ; store tens
xchg ah,al ; get units back
stosb ; store byte at ES:DI
ret
iend outi
internal rdclk ; read the CLOCK$ device
mov dx,offset clknam ; open CLOCK$
mov ax,3d00h
int 21h
jc nogo
mov bx,ax ; read the date
mov cx,1
mov dx,offset days
mov ah,3fh
int 21h
jc nogo
mov ah,3eh ; release the handle
int 21h
nogo: ret
iend rdclk
finish